import pdftxt from '@/assets/pdfs/pdftxt.pdf';
import gf1 from '@/assets/imgs/gf1.png';
import gf2 from '@/assets/imgs/gf2.png';
import gf3 from '@/assets/imgs/gf3.png';
import gf4 from '@/assets/imgs/gf4.png';
import gf5 from '@/assets/imgs/gf5.png';
import gf6 from '@/assets/imgs/gf6.jpeg';
import gf7 from '@/assets/imgs/gf7.jpeg';
import gf8 from '@/assets/imgs/gf8.jpeg';
import gf9 from '@/assets/imgs/gf9.jpeg';
import gf10 from '@/assets/imgs/gf10.jpeg';
import cluster from '@turf/clusters-kmeans';
import dig2 from '@/assets/imgs/dig2.png';
import dig3 from '@/assets/imgs/dig3.png';
import dig4 from '@/assets/imgs/dig4.png';
import report1 from '@/assets/imgs/report1.png';
import report2 from '@/assets/imgs/report2.png';
import reportGuangfu from '@/assets/pdfs/reportGuangfu.pdf';

// 监测是否是本地
export const isLocal = () => window.location.hostname === 'localhost';

export const wait = (time: number = 1000) =>
  new Promise((resolve) => setTimeout(() => resolve(true), time));

export const mapStyle = 'https://api.maptiler.com/maps/streets/style.json?key=3EojNgis3jpQesSHthKP';

export const meums = [
  { name: 'Home', path: '/home' },
  { name: 'Report', path: '/report' },
  { name: 'Demo', path: '/demo' },
  { name: 'Contact US', path: '/contactUs' },
];

export const homeGunDongs = [
  'https://framerusercontent.com/images/qt351dPq4ItFDPnleEv6lADBEU.webp',
  'https://framerusercontent.com/images/64a1Wm045p3BCteuC6u8tRKB8.png',
  'https://framerusercontent.com/images/vjTbTVuLRCRoRtdWnhmihmd08.png',
  'https://framerusercontent.com/images/b17e7gyEoGDZBxk0cCAdKsAQR30.webp',
  'https://framerusercontent.com/images/TEcdnZTgwWocmdH85HIo9894B1M.png',
  'https://framerusercontent.com/images/tEWXksqg2HYZjo0iAVikUNRo.png',
  'https://framerusercontent.com/images/GYeXrOraJq9qUibNEwYgHaaC0Iw.png',
  'https://framerusercontent.com/images/Ap8GlwyZp6N8T1WCYAbgrrCykA.png',
  'https://framerusercontent.com/images/YdDO0CyjwTC8Pv7dF3nNwNjVXhU.png',
  'https://framerusercontent.com/images/CrSpLedl0NNJee4wwEnGligmH6o.svg',
  'https://framerusercontent.com/images/IzznCbc7DN5z1O4Bm9TPPh8Vbxs.png',
];

export const homePeoples = [
  {
    logo: 'https://framerusercontent.com/images/alahURYP2fCm1Kpd9KzYt3jESgg.png',
    txt: 'We are a vertically integrated IPp, which means we build, own, and operate our assets.That requires long - termthinkina and reliable data over the lifetime of our assets.Raptor Maos aives us the information we need so that wecan focus on what matters - delivering clean energy efficiently and reliably.',
    botImg: 'https://framerusercontent.com/images/Cavf5e2QaNZg9zDSuNv7DC492zc.png',
    botTxt: 'Neil James | VP Operations and Maintenance',
  },
  {
    logo: 'https://framerusercontent.com/images/a63qJZmhibVe1IOtWyOnisy0I.png',
    txt: 'Raptor Maps meets our mandate of leveraging state-of-the-art technology to scale our operations and ensure maximum performance for our clients.',
    botImg: 'https://framerusercontent.com/images/iq1lj5x9N59XSVoaOh9suO8uA.jpeg',
    botTxt: 'Kyle Cooper | CEO',
  },
  {
    logo: 'https://framerusercontent.com/images/DY6SmkAUBCXUjf0rlb97VJLim9s.png',
    txt: 'Combining our expertise, Raptor Maps’ software, and this in-house drone program is going to give our operations a superpower in delivering world-class services to our partners. These solutions will truly empower our teams, enhancing capabilities from the control room, to our Performance Engineers & technicians out in the field.',
    botImg: 'https://framerusercontent.com/images/8gfCI9tjZ3OfUUTUdFbi8nC9xFs.jpeg',
    botTxt: 'Sean Bucher | BayWa r.e Operations Services',
  },
  {
    logo: 'https://framerusercontent.com/images/IGOB2Hhlve7gt0dLqmLrgLutKZY.png',
    txt: 'Partnering with Raptor Maps allows us to manage our portfolio with high confidence and to deploy resources efficiently. Our company prides itself as a creative implementer and a pragmatic problem solver, so it’s critical for us to have a software partner that aligns with our company mission.',
    botImg: 'https://framerusercontent.com/images/z5Rxnw9We5GmJBitQcez3nYWknY.png',
    botTxt: 'Ramon Almodovar | Director of BESS and Solar FIeld Services ',
  },
];

export const homeRapids = [
  {
    title: 'Monitor erosion',
    img: 'https://framerusercontent.com/images/KAVz3bQZkYCnvxtNQSnzkEnoNw.png',
  },
  {
    title: 'Verify construction',
    img: 'https://framerusercontent.com/images/zxAbO4yxa2cqVWGu79fhfvgbXM.png',
  },
  {
    title: 'Investigate alerts',
    img: 'https://framerusercontent.com/images/q481e2IylLE3SatxU6gAK7LnU.png',
  },
  {
    title: 'Detect cracks',
    img: 'https://framerusercontent.com/images/ajrYOPhS7eR2ffdL7rcGEPR1A.png',
  },
  {
    title: 'Inspect interconnection',
    img: 'https://framerusercontent.com/images/4niNYj9Djqy0cDNyrzrcnNWVQ.png',
  },
  {
    title: 'Manage wiring',
    img: 'https://framerusercontent.com/images/kSUihdCBpCHfdXJdBfSJqVdNm6E.png',
  },
  {
    title: 'Storm response',
    img: 'https://framerusercontent.com/images/EeA6FSifvplmG6rs2KlnM7Kx9c.png',
  },
  {
    title: 'Mitigate fire risks',
    img: 'https://framerusercontent.com/images/wUoNF1t1dYeBaU5dNoxjtEuBY.png',
  },
  {
    title: 'Manage Dc health',
    img: 'https://framerusercontent.com/images/kPtqkrX0P4we9TbIIohgEnmVm6U.png',
  },
  {
    title: 'Livestream',
    img: 'https://framerusercontent.com/images/jkrhDYpZz24nXowi9eEkUKCnQ.png',
  },
];
export const homeRaptors = [
  {
    title: 'For utility-scale asset owners',
    desc: 'Activate proof-of-concept',
    img: 'https://framerusercontent.com/images/LRZOhgBIGxAmyTUnR1vV1oC88RU.jpg',
  },
  {
    title: '',
    desc: 'Get a demo',
    img: 'https://framerusercontent.com/images/4XNSnZDImsqgpnu6PIy0b7YQC4.png',
  },
];

/*
模块 Related Resources
  View all resources
  超3行显示省略号
*/
export const ResourcesDatas = [
  {
    title: '2025 Global Solar Report',
    desc: "Download this year's report on the state of PV performance.Drawing from 193 GWdc of analysis, the report dives into industry trends that are impacting the market, how leading asset owners and operators are tackling the evolving risk profiles challenging growth and scalability, and detailed performance trends.Take a sneak peak of this year's findings below.",
    img: 'https://framerusercontent.com/images/SDSRy3S6MFvGrbopvYIiqdCL4.webp',
  },
  {
    title: 'New Feature Highlights and General Platform Orientation - June 2025',
    desc: "Whether you're new or just want a refresher, we’re hosting a short, informative webinar to help you confidently navigate the platform.",
    img: 'https://framerusercontent.com/images/txF16ucPaDy79v9yKbaPCfSLE.png',
  },
  {
    title: 'A New BMP for Erosion and Stormwater Management in Solar',
    desc: 'Maintaining erosion control best management practices(BMPs) and preventing stormwater pollution is crucial at every phase of the solar project, but it can also be costly, time- intensive, and difficult to do at scale.Especially during the construction phase as the land recovers from civil work and grading, vegetation is still taking root and there is a lot of heavy traffic on site.This article provides three(3) tips to increase the effectiveness of your SWPPPs and the efficiency of erosion - related inspection & maintenance efforts, applying to both the construction and operational phases of the solar project.',
    img: 'https://framerusercontent.com/images/4XNSnZDImsqgpnu6PIy0b7YQC4.png',
  },
];

export const ReportDats = [
  {
    img: report1,
    href: reportGuangfu,
    txt: null,
  },
  {
    img: report2,
    href: 'http://scopito.com/wp-content/uploads/2021/04/WTG-Blade-Report-Scopito.pdf',
    txt: 'Coming Soon',
  },
];

export const homeDigitalImgs = [
  'https://framerusercontent.com/images/hBzdMSfUJfTbuGMs0aH5eCtluU.gif',
  dig2,
  dig3,
  dig4,
  'https://framerusercontent.com/images/tNxPsezI1X5CJwlUcZGB8t5Il0.png',
];

export const electricityOptions = {
  1: '0-50 MW',
  2: '50-250MW',
  3: '250-500MW',
  4: '500MW-1GW',
  5: '1GW+',
};

// 模拟坐标，经纬度数据
export const zuoBiaos = [
  {
    id: 1,
    city: '北京',
    // longitude: 116.407526,
    // latitude: 39.90403,
    longitude: 149.12431031934818,
    latitude: -33.30932363747079,
    created: 'Jun 6, 2025.11:28:42 AM', // 原始时间（第1条）
    renews: '-',
    inspection: '2.4MW Simplified Solar Inspector 1', // 后缀加1
    company: 'dd_1', // 后缀加1
    type: 'Solar Panels',
    images: '179', // 原始值（若需递增则改为179+0=179，此处按示例可能需调整）
    assets: '-',
  },
  {
    id: 2,
    city: '上海',
    // longitude: 121.473701,
    // latitude: 31.230416,
    longitude: 150.89611760741195,
    latitude: -33.610600117123184,
    created: 'Jun 6, 2025.11:29:42 AM', // 时间递增1分钟
    renews: '-',
    inspection: '2.4MW Simplified Solar Inspector 2', // 后缀加2
    company: 'dd_2', // 后缀加2
    type: 'Solar Panels',
    images: '180', // 数值递增1（假设原始179为起始值）
    assets: '-',
  },
  {
    id: 3,
    city: '广州',
    // longitude: 113.264394,
    // latitude: 23.129107,
    longitude: 147.41509910665826,
    latitude: -35.09150293515129,
    created: 'Jun 6, 2025.11:30:42 AM', // 时间递增1分钟
    renews: '-',
    inspection: '2.4MW Simplified Solar Inspector 3', // 后缀加3
    company: 'dd_3', // 后缀加3
    type: 'Solar Panels',
    images: '181', // 数值递增1
    assets: '-',
  },
  {
    id: 4,
    city: '深圳',
    // longitude: 114.057865,
    // latitude: 22.543096,
    longitude: 150.37924703321215,
    latitude: -35.51406611606876,
    created: 'Jun 6, 2025.11:31:42 AM', // 时间递增1分钟
    renews: '-',
    inspection: '2.4MW Simplified Solar Inspector 4', // 后缀加4
    company: 'dd_4', // 后缀加4
    type: 'Solar Panels',
    images: '182', // 数值递增1
    assets: '-',
  },
  {
    id: 5,
    city: '杭州',
    // longitude: 120.1529,
    // latitude: 30.2718,
    longitude: 147.11497738075525,
    latitude: -38.158310531731516,
    created: 'Jun 6, 2025.11:32:42 AM', // 时间递增1分钟
    renews: '-',
    inspection: '2.4MW Simplified Solar Inspector 5', // 后缀加5
    company: 'dd_5', // 后缀加5
    type: 'Solar Panels',
    images: '183', // 数值递增1
    assets: '-',
  },
];

const gfImg: any = [gf1, gf2, gf3, gf4, gf5, gf6, gf7, gf8, gf9, gf10];
export const gfImgs = [...gfImg, ...gfImg];

export const realImgs = (number: number) => {
  const num = Math.ceil(number / 10);
  const erWei: any = [];
  const allImgs = [];
  for (let i = 0; i < num; i++) {
    const jnum = i === num - 1 ? number % 10 : 10;
    erWei[i] = [];
    for (let j = 0; j < jnum; j++) {
      const tmp: any = Math.floor(Math.random() * 10);
      erWei[i].push(gfImg[tmp]);
      allImgs.push(gfImg[tmp]);
    }
  }
  return { allImgs, erWei };
};

function countNum(num: number) {
  const suiji = Math.random() * 0.002;
  let res = 0;
  if (Math.random() > 0.5) {
    res = num + suiji;
  } else {
    res = num - suiji;
  }
  return res;
}

// 点颜色
const redBg = '#b14434';
const defBg = '#57afb9';

// 生成模拟点
export const getMockPoint = (
  count: number = 20,
  long: number = 116.457526,
  lat: number = 39.90403,
) => {
  const result = [];
  const redId = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100];
  for (let i = 0; i < count; i++) {
    result.push({
      id: `point-${i}`,
      coordinates: [countNum(long), countNum(lat)],
      properties: { name: `点 ${i}`, value: Math.random() * 1 },
      color: `${redId.includes(i) ? redBg : defBg}`,
    });
  }
  return result;
};

// 计算聚合点
export const getClusterPoint = (points: any, zoom: number) => {
  if (points.length === 0) return;
  // 根据缩放级别确定聚类数量
  let clusterCount = 10;
  if (zoom > 15) clusterCount = 10000;
  else if (zoom > 14.5) clusterCount = 170;
  else if (zoom > 14.3) clusterCount = 150;
  else if (zoom > 14.2) clusterCount = 130;
  else if (zoom > 14.1) clusterCount = 30;
  else if (zoom > 14) clusterCount = 20;
  else if (zoom > 13.8) clusterCount = 10;
  else if (zoom > 13.5) clusterCount = 5;
  else if (zoom > 13) clusterCount = 2;
  // else if (zoom > 12) clusterCount = 2;
  else if (zoom > 1) clusterCount = 1;

  const pointsFeatureCollection: any = {
    type: 'FeatureCollection',
    features: points.map((point: any) => ({
      type: 'Feature',
      geometry: {
        type: 'Point',
        coordinates: point.coordinates,
      },
      properties: {
        id: point.id,
        ...point.properties,
      },
    })),
  };

  const clustered = cluster(pointsFeatureCollection, {
    numberOfClusters: clusterCount,
    mutate: false,
  });

  // 转换聚类结果为聚合点格式
  const clustersMap: any = {};

  clustered.features.forEach((feature) => {
    const clusterId = feature.properties?.cluster;
    const pointId = feature.properties?.id;

    if (clusterId === undefined || pointId === undefined) return;

    const point = points.find((p) => p.id === pointId);
    if (!point) return;

    if (!clustersMap[clusterId]) {
      clustersMap[clusterId] = {
        id: `cluster-${clusterId}`,
        coordinates: [0, 0],
        points: [],
        count: 0,
      };
    }

    clustersMap[clusterId].points.push(point);
    clustersMap[clusterId].count++;
  });

  // 计算每个聚类的中心点
  const result: any[] = Object.values(clustersMap).map((cluster: any) => {
    const sumX = cluster.points.reduce((sum: any, p: any) => sum + p.coordinates[0], 0);
    const sumY = cluster.points.reduce((sum: any, p: any) => sum + p.coordinates[1], 0);

    return {
      ...cluster,
      coordinates: [sumX / cluster.count, sumY / cluster.count],
    };
  });
  return result;
};

export const getSize = (size: number) => {
  let num = 30;
  if (size > 100) {
    num = 34;
  } else if (size > 20) {
    num = 28;
  } else if (size > 10) {
    num = 22;
  } else {
    num = 12;
  }
  return num;
};

export const getJHDBg = (list: any) => {
  const arr: any[] = [];
  list.forEach((item: any) => {
    if (arr.includes(item.color)) return;
    arr.push(item.color);
  });
  const color = arr.includes(redBg) ? redBg : defBg;
  return color;
};

// 根据经纬度计算img数量
export const getImgCount = (list: any, long: number, lat: number) => {
  let num = 0;
  list.forEach((item: any) => {
    if (item?.longitude === long && item?.latitude === lat) {
      console.log('item: ', item);
      num = item?.images;
    }
  });
  console.log('num: ', num);
  return num;
};
